package com.guoheng.hazard.sys.service.impl.entpr;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guoheng.hazard.common.base.Result;
import com.guoheng.hazard.sys.mapper.entpr.EntprLicenseInfoMapper;
import com.guoheng.hazard.sys.model.dto.entpr.EntprLicenseInfoInsertDTO;
import com.guoheng.hazard.sys.model.dto.entpr.EntprLicenseInfoUpdateDTO;
import com.guoheng.hazard.sys.model.entity.entpr.EntprLicenseInfo;
import com.guoheng.hazard.sys.service.entpr.EntprLicenseInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 类功能描述:　证照信息
 *
 * @author fbl
 * @date 2019-11-12 09:27
 */
@Service
public class EntprLicenseInfoServiceImpl implements EntprLicenseInfoService {

    @Resource
    EntprLicenseInfoMapper entprLicenseInfoMapper;

    @Override
    public Result getEntprLicense(Long entprId,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<EntprLicenseInfo> entprLicense = entprLicenseInfoMapper.getEntprLicense(entprId);
        PageInfo<EntprLicenseInfo> entprLicenseInfoPageInfo = new PageInfo<>(entprLicense);
        return Result.success(entprLicenseInfoPageInfo);
    }

    @Override
    public Result updateEntprLicense(@Valid EntprLicenseInfoUpdateDTO entprLicenseInfoUpdateDTO) {
        EntprLicenseInfo entprLicenseInfo = new EntprLicenseInfo();
        BeanUtils.copyProperties(entprLicenseInfoUpdateDTO,entprLicenseInfo);
        entprLicenseInfoMapper.updateEntprLicense(entprLicenseInfo);
        return Result.success();
    }

    @Override
    public Result insertEntprLicense(EntprLicenseInfoInsertDTO entprLicenseInfoInsertDTO) {
        EntprLicenseInfo entprLicenseInfo = new EntprLicenseInfo();
        BeanUtils.copyProperties(entprLicenseInfoInsertDTO,entprLicenseInfo);
        entprLicenseInfoMapper.insertEntprLicense(entprLicenseInfo);
        return Result.success();
    }

    @Override
    public Result deleteEntprLicense(Long id) {
        EntprLicenseInfo entprLicenseInfo = new EntprLicenseInfo();
        entprLicenseInfo.setEntprId(id);
        entprLicenseInfo.setDelFlag(true);
        entprLicenseInfoMapper.updateEntprLicense(entprLicenseInfo);
        return Result.success();
    }

    @Override
    public Result getEntprLicenseById(Long id) {
        return  Result.success(entprLicenseInfoMapper.getEntprLicensesById(id));
    }
}